package com.settlement.system.controller;

import com.settlement.system.csv.CsvExportBuilder;
import com.settlement.system.csv.CsvExportUtil;
import com.settlement.system.common.enums.ExcelFileType;
import com.settlement.system.model.entity.common.TblWpThreeReturnSummary;
import com.settlement.system.service.IBaseService;
import com.settlement.system.service.csv.DateSpiltCsvDatas;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import com.settlement.system.model.entity.common.TblWpThreeReturnRecord;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import com.settlement.system.service.ITblWpThreeReturnRecordService;

import java.io.File;
import java.util.Map;

/**
 * WP-三退退供单汇总-存档记录表 前端控制器
 * @author xiaochuan
 * @since 2022-08-26
 */

@Api(tags = "WP-三退退供单汇总-存档记录表",description = "WP-三退退供单汇总-存档记录表")
@RestController
@RequestMapping("/wp/tblWpThreeReturnRecord")
public class TblWpThreeReturnRecordController extends ExcelController<TblWpThreeReturnRecord> {

    @Value("${system.export-root.path}")
    private String exportRootPath;

    @Resource
    private ITblWpThreeReturnRecordService tblWpThreeReturnRecordService;

    @Override
    public IBaseService init() {
        return tblWpThreeReturnRecordService;
    }

    @Override
    public Class<?> getModelClass() {
        return TblWpThreeReturnRecord.class;
    }

    @Override
    public void exportExcelPost(HttpServletRequest request, HttpServletResponse response, @RequestBody Map<String, Object> params) throws Exception {
        setParamsModel(params);
        String fileName = "WP-三退退供单汇总-存档记录";
        String path = exportRootPath + System.currentTimeMillis() + File.separator;
        CsvExportUtil.createCsv()
                .headClass(TblWpThreeReturnRecord.class)
                .fileName(fileName)
                .fileType(ExcelFileType.XLSX)
                .model(CsvExportBuilder.MULTI_ZIP_MODEL)
                .parentPath(path)
                .csvDatas(new DateSpiltCsvDatas(tblWpThreeReturnRecordService, params))
                .export(request, response);
    }
}

